﻿using System;
using System.Collections.Generic;
using System.Linq;
using SystemTypes;
using System.Text.RegularExpressions;

namespace NetSettings
{
    [Serializable]
    public class Question
    {
        public Types.QuestionTypes QuestionType;
        public List<Types.ArcType> SupportedArcs;
        public string QuestionPattern;
        public string AnswerPattern;
        public Question()
        {
            QuestionType = Types.QuestionTypes.Undefined;
            SupportedArcs=new List<Types.ArcType>();
            QuestionPattern = "";
            AnswerPattern = "";
        }
        public Question(Types.QuestionTypes questionType, List<Types.ArcType> supportedArcs, string qpattern, string apattern)
        {
            QuestionType = questionType;
            SupportedArcs = supportedArcs;
            QuestionPattern = qpattern;
            AnswerPattern = apattern;
        }
    }

    [Serializable]
    public class Questions
    {
        public List<Question> QuestionsData;
        public Questions()
        {
            QuestionsData = new List<Question>();
        }
        public Questions(List<Question> questionPattern)
        {
            QuestionsData = questionPattern;
        }

        public Question GetQuestionByTypeName(string typeName)
        {
            return QuestionsData.FirstOrDefault(question => question.QuestionType.ToString() == typeName);
        }
        public Question GetQuestionByType(Types.QuestionTypes type)
        {
            return QuestionsData.FirstOrDefault(question => question.QuestionType == type);
        }

        public void OverwriteQuestionSameType(Question newQuestion)
        {
            var oldQuestion = GetQuestionByType(newQuestion.QuestionType);
            QuestionsData.Remove(oldQuestion);
            QuestionsData.Add(newQuestion);
        }
    }

    [Serializable]
    public class Settings
    {
        public Questions QuestionsInfo;

        public Settings()
        {
            QuestionsInfo = new Questions();
        }

        public bool Validate(string regularExpression, string theString)
        {
            return Regex.IsMatch(theString, regularExpression, RegexOptions.IgnoreCase);
        }
    }
}
